<template>
  <div>
    <div class="scroll-container">
      <!-- 表格展示 -->
      <el-table v-loading="loading" :data="InfoAuditing" border @sort-change="handleSortChange"
                @selection-change="handleSelectionChange">
        <!--缩略图-->
        <el-table-column align="center" label="头像" prop="avatarUrl" width="180">
          <template #default="scope">
            <el-image :lazy="true" :src="scope.row.avatarUrl" class="image-cover" fit="cover">
              <div slot="error" class="image-slot">
                <i class="el-icon-picture-outline"></i>
              </div>
            </el-image>
          </template>
        </el-table-column>
        <el-table-column align="center" label="姓名" prop="name" ></el-table-column>
        <el-table-column align="center" label="学号" prop="studentNum"></el-table-column>
        <el-table-column align="center" label="年级" prop="grade"></el-table-column>
        <el-table-column align="center" label="申请时间" prop="createTime">
          <template #default="scope">
            <div class="time">
              <svg-icon icon-file-name="time"></svg-icon>
              <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
            </div>
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column align="center" label="操作">
          <template #default="scope">
            <el-button class="sdf" link type="primary" @click="handlePass(scope.row.studentId)">
              <svg-icon icon-file-name="edit"></svg-icon>
              通过
            </el-button>
            <el-button class="sd" link type="danger" @click="handleDelete(scope.row.studentId)">
              <svg-icon icon-file-name="delete"></svg-icon>
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页组件 -->
    <pagination v-if="total > 0" :limit="pagInfo.pageSize" :page="pagInfo.currentPage" :total="total"
                style="float: right;" @pagination="getStudentAuditingList"
                @update_limit="pagInfo.pageSize = $event"
                @update_page="pagInfo.currentPage = $event"/>
  </div>
</template>

<script>
import Pagination from "@/common/pagination.vue";
import {deleteStudentInfo, getStudentAuditing, passStudentInfo} from "@/apis/admin";

export default {
  // 组件注册，允许在模板中使用导入的组件
  components: {
    Pagination, // 分页组件
  },
  // 组件的响应数据对象
  data() {
    return {
      // 控制搜索表单显示的布尔值
      showSearch: true,
      // 搜索参数对象
      queryParams: {
        name: '', // 课程名
        teacherName: '', // 任课老师姓名
      },
      //分页信息
      pagInfo: {
        currentPage: 1,
        pageSize: 10
      },
      // 存储待审核信息列表的数组
      InfoAuditing: [],
      // 控制表格加载状态的布尔值
      loading: false,
      // 存储总的待审核信息的数量的变量
      total: 0,

      formLabelWidth: '120px', // 表单标签宽度
    };
  },
  methods: {
    // 处理通过按钮点击事件
    handlePass(studentId) {
      let data = {
        studentId: studentId
      }
      passStudentInfo(data).then(res => {
        if (res.data.code === 1){
          this.$message.success(res.data.data);
          this.getStudentAuditingList();
        } else {
          this.$message.error(res.data.msg);
        }
      })

    },
    // 前端排序函数
    handleSortChange({prop, order}) {
      if (!order) {
        // 如果没有排序顺序，可能是恢复到未排序状态
        this.getStudentAuditingList();
        return;
      }

      this.InfoAuditing.sort((a, b) => {
        if (order === 'ascending') {
          return a[prop] - b[prop]; // 升序排序
        } else {
          return b[prop] - a[prop]; // 降序排序
        }
      });
    },
    // 处理表格行选择事件
    handleSelectionChange(selection) {
      this.courseIdList = selection.map(item => item.id);
    },
    // 处理不通过按钮点击事件
    handleDelete(studentId) {
      let data = {
        studentId: studentId
      }
      deleteStudentInfo(data).then(res => {
        if (res.data.code === 1){
          this.$message.success(res.data.data);
          this.getTeacherAuditingList();
        } else {
          this.$message.error(res.data.msg);
        }
      })
    },
    // 获取学生注册审核信息的方法
    async getStudentAuditingList() {
      this.loading = true;
      const pagination = {
        currentPage: this.pagInfo.currentPage,
        pageSize: this.pagInfo.pageSize
      }
      const queryParams = null;
      const DTOdata = {
        pagination,
        queryParams
      }
      await getStudentAuditing(DTOdata).then(res => {
        if (res.data.code === 1) {
          res.data.data.list.forEach((course) => {
            course.createTime = this.$common.dateFormat(course.createTime);
          });
          this.InfoAuditing = res.data.data.list;
          this.total = res.data.data.total;
          this.loading = false;
        } else {
          this.$message.error(res.data.msg);
        }
      })
    }
  },
  created() {
    this.getStudentAuditingList();
  }
};
</script>

<style scoped>

.scroll-container {
  max-height: 646px; /* 您可以根据需要调整这个值 */
  overflow-y: auto;
}

.sdf {
  background: transparent;
  border-color: transparent;
  color: #76d7ff;
}

.sd {
  background: transparent;
  border-color: transparent;
  color: #fa1224;
}

.image-cover {
  width: 100px;
  height: 60px;
  border-radius: 5px;
  overflow: hidden;
  cursor: pointer;

  .image-slot {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f7fa;
    color: #909399;
  }
}

.time {
  display: flex;
  align-items: center;
}
</style>

